<?php
namespace app\mall_back\controller;

use app\data\model\DataUser;
use app\mall\logic\walletLogic;
use app\mall_back\model\WithdrawApplyModel;
use think\admin\Controller;
use think\facade\Db;

class WithdrawApply extends Controller{

    /**
     * 提现管理
     * @auth true
     */
    public function index(){
        WithdrawApplyModel::mQuery()->where(['cate'=>1])->layTable(function () {
            $this->title = '提现记录';
        });
    }

    //表单数据处理
    protected function _form_filter(array &$data){
        if ($this->request->isPost()) {

            if (!isset($data['status'])){
                $this->error('请选择审核状态！');
            }
            if ($data['status']==2){
                if (empty($data['transfer_voucher'])){
                    $this->error('请上传转账凭证！');
                }
                $data['update_time'] = time();
                $data['transfer_time'] = time();
            }
            if ($data['status']==3){
                if (empty($data['description'])){
                    $this->error('提现失败请填写备注！');
                }

                $data['update_time'] = time();
                //回退提现金额
                Db::table('one_user_wallet')->where('u_id','=',$data['u_id'])->inc('integral',$data['spend_money'])->update();//增加余额
                //更新积分变更记录
                walletLogic::wallet_detailed_add($data['u_id'],$data['spend_money'],5,2,0,'add','提现失败回退');//增加记录
            }
        }

    }


    //数据列表处理
    protected function _page_filter(array &$data)
    {
        foreach ($data as $k => &$v){
            $v['user_phone'] = DataUser::where('id','=',$v['u_id'])->value('phone');
        }

    }

    /**
     * 添加问题
     * @auth true
     */
    public function add()
    {
        WithdrawApplyModel::mForm('form');
    }

    /**
     * 修改问题
     * @auth true
     */
    public function edit()
    {
        WithdrawApplyModel::mForm('form');
    }

    /**
     * 删除问题
     * @auth true
     */
    public function remove(){
//        $id = request()->param('id',0);
//        WithdrawApplyModel::where('id','=',$id)->delete();
//        $this->success('数据删除成功');
    }


}